package com.warmlight.voicepacket;

import android.Manifest;
import android.app.ActivityManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.google.gson.Gson;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import com.karumi.dexter.listener.single.PermissionListener;
import com.umeng.analytics.MobclickAgent;
import com.warmlight.voicepacket.base.BaseActivity;
import com.warmlight.voicepacket.common.OttoConstants;
import com.warmlight.voicepacket.data.VersionCheck;
import com.warmlight.voicepacket.data.eventbus.TeaseHideFloat;
import com.warmlight.voicepacket.db.SharePreferenceUtil;
import com.warmlight.voicepacket.db.SharedPerfenceConstant;
import com.warmlight.voicepacket.dbdata.DBFloatPlaylist;
import com.warmlight.voicepacket.dbmanager.DBFloatPlayListDaoHelp;
import com.warmlight.voicepacket.fragment.MeFragment;
import com.warmlight.voicepacket.fragment.RecommendFragment;
import com.warmlight.voicepacket.http.Callback;
import com.warmlight.voicepacket.http.HttpClient;
import com.warmlight.voicepacket.http.HttpConfig;
import com.warmlight.voicepacket.ottoEvent.ORecommBean;
import com.warmlight.voicepacket.ottoEvent.OVideoBean;
import com.warmlight.voicepacket.ottoEvent.OttoBus;
import com.warmlight.voicepacket.plugin.QmzbVideoPlayer;
import com.warmlight.voicepacket.utils.DownloadHelper;
import com.warmlight.voicepacket.utils.ImConnect;
import com.warmlight.voicepacket.utils.MobClickHelper;
import com.warmlight.voicepacket.utils.SPUtils;
import com.warmlight.voicepacket.utils.TimeFormatUtils;
import com.zhuge.analysis.stat.ZhugeSDK;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;

import okhttp3.Call;

//import cn.sharesdk.onekeyshare.OnekeyShare;

public class MainActivity extends BaseActivity implements PermissionListener{

//    private long mExitTime;
//    private static long DURING = 2000;
    private RelativeLayout main_tab;
    private RadioGroup rg_bottombar;
//    private FrameLayout mFragmentContainer;
    private HashMap<Integer, String> mTabsMap;
    private HashMap<Integer, Fragment> fragmentMap;
//    private int prePageIndex = 0;
//    private Fragment currentFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //融云初始化
//        TreeMap map =new TreeMap();
        ImConnect.getInstance().RongConnect(getContext());
        ImConnect.getInstance().SetUserProvide();

        init();
        initPlaylist();
        startService(new Intent(MainActivity.this,AudioService.class));
//        testPermission();
        //检测悬浮窗权限放在相应位置
//        checkPermission();

        //20180628-新的悬浮窗权限逻辑，added by jason
//        checkFloatWindowPermission();

        createWindow();
//        showShare();
        checkNultPermission();

        checkVersion();
        ZhugeSDK.getInstance().init(getApplicationContext());
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();

        ZhugeSDK.getInstance().flush(getApplicationContext());
        System.gc();
    }



    /**
     * 判断某个服务是否正在运行的方法
     *
     * @param mContext
     * @param serviceName 是包名+服务的类名（例如：com.baidu.trace.LBSTraceService）
     * @return true代表正在运行，false代表服务没有正在运行
     */
    public boolean isServiceWork(Context mContext, String serviceName) {
        boolean isWork = false;
        ActivityManager myAM = (ActivityManager) mContext
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> myList = myAM.getRunningServices(80);
        if (myList.size() <= 0) {
            return false;
        }
        for (int i = 0; i < myList.size(); i++) {
            String mName = myList.get(i).service.getClassName().toString();
            if (mName.equals(serviceName)) {
                isWork = true;
                break;
            }
        }
        return isWork;
    }


    //监测版本
    private void checkVersion(){
        TreeMap<String, String> map = new TreeMap<>();
        map.put("version",packageName());
        map.put("app_id","1");

        HttpClient.post(HttpConfig.SERVER+ HttpConfig.VERSION, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                Log.i("WLVP","获取服务器版本号失败");
            }

            @Override
            public void onResponse(Call call, final String response) {
                try {
//                    final String s = response.body().string();
                    final VersionCheck data = new Gson().fromJson(response,VersionCheck.class);

                    (MainActivity.this).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
//                            Log.e("TAG","response="+response);
                            if(data != null && data.getData() != null){
                                if(data.getData().isIs_upgrade()){
//                                    Log.e("Version","需要升级");

                                    showVersionDialog(data.getData());

                                }else{
//                                    Log.e("Version","不需要升级");
                                }
                            }
                        }
                    });
                }catch (Exception e){

                }
            }
        });
    }

    private void showVersionDialog(final VersionCheck.DataBean data){
        if (data.isIs_force()){
            downloadAPK(data.getDownload_url());
        }else{
            AlertDialog.Builder builder = new AlertDialog.Builder(this,android.R.style.Theme_Material_Light_Dialog_Alert).setTitle("版本更新")
                    .setMessage(data.getDesc())
                    .setNegativeButton(data.getConfirm_txt(), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            downloadAPK(data.getDownload_url());
                        }
                    }).setPositiveButton(data.getCancel_txt(), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            builder.create().show();
        }
    }

    private void downloadAPK(String download_url){
        showProgressDialog();
        DownloadHelper.getInstance().download(download_url, "voicepacket.apk", new DownloadHelper.OnDownloadListener() {
            @Override
            public void onDownloadSuccess(final File file) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        hideProgressDialog();
                        anzhuang(file);
                    }
                });

            }

            @Override
            public void onDownloading(final int progress) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        setmProgressDialog(progress);
                    }
                });
            }

            @Override
            public void onDownloadFailed(Exception e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        hideProgressDialog();
                        showToast("下载失败，请稍后再试");
                    }
                });
            }
        });
    }

    private void anzhuang(File file){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(MainActivity.this, "com.warmlight.voicepacket.FileProvider", file);
            intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        startActivity(intent);
        //强制更新就把应用关掉
//        android.os.Process.killProcess(android.os.Process.myPid());
    }

    private ProgressDialog mProgressDialog;

    private void showProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog.setTitle("下载更新");
        mProgressDialog.setMax(100);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setCanceledOnTouchOutside(false);
//        mProgressDialog.setProgressDrawable(this.getResources()
//                .getDrawable(R.drawable.seekbar_progress));
        mProgressDialog.show();
    }

    private void setmProgressDialog(int progress){
        if (mProgressDialog != null){
            mProgressDialog.setProgress(progress);
        }
    }

    private void hideProgressDialog(){
        if (mProgressDialog != null){
            mProgressDialog.dismiss();
        }
    }

    public int packageCode() {
        PackageManager manager = MainActivity.this.getPackageManager();
        int code = 0;
        try {
            PackageInfo info = manager.getPackageInfo(MainActivity.this.getPackageName(), 0);
            code = info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return code;
    }

    public String packageName() {
        PackageManager manager = MainActivity.this.getPackageManager();
        String code = "";
        try {
            PackageInfo info = manager.getPackageInfo(MainActivity.this.getPackageName(), 0);
            code = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            code = BuildConfig.VERSION_NAME;
        }
        return code;
    }

    private void initPlaylist(){
        if(!SPUtils.isPlaylistCreated()){
            //如果没创建我的最爱播单则创建，否则跳过
            DBFloatPlaylist listData = new DBFloatPlaylist(null,"", "我的最爱", "", "0", "", "");
//            DBHelper.getInstance(MainActivity.this).addList(listData);
            DBFloatPlayListDaoHelp.insert(this,listData);
            SPUtils.setPlaylistCreated(true);
        }

    }

    private void  checkNultPermission(){
        if(Build.VERSION.SDK_INT >= 23) {
            //判断是否有权限请求没被处理
            if (Dexter.isRequestOngoing()) {
                return;
            }
            //请求权限
            Dexter.checkPermissions(new MultiplePermissionsListener() {
                @Override
                public void onPermissionsChecked(MultiplePermissionsReport report) {

                }

                @Override
                public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
                    if(!SPUtils.isPermissionNoticed()){
                        showRationaleShouldBeShownDialog(token);
                        SPUtils.setPermissionNotice(true);
                    }
                }
            }, Manifest.permission.CAMERA,Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION);
        }else{
        }
    }
    private void testPermission(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if(!Settings.canDrawOverlays(getApplicationContext())) {
                //启动Activity让用户授权
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                intent.setData(Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent,100);
            }
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (Settings.canDrawOverlays(this)) {
                    createWindow();
                }
            } else {
                showToast("ACTION_MANAGE_OVERLAY_PERMISSION权限已被拒绝");
            }
        }

    }

//    public FragmentManager getSupportFragment(){
//        return getSupportFragmentManager();
//    }

    //检查并申请权限
    private void checkPermission(){
        if(Build.VERSION.SDK_INT >= 23){
            if (Dexter.isRequestOngoing()) {
                return;
            }
            Dexter.checkPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);
//            Dexter.checkPermissions(new MultiplePermissionsListener() {
//                @Override
//                public void onPermissionsChecked(MultiplePermissionsReport report) {
//
//                }
//
//                @Override
//                public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
//
//                }
//            });
        }else{
//            Log.e("TAG","版本小于23");
        }
    }

    /**
     * 初始化
     */
    private void init(){
        main_tab = (RelativeLayout) findViewById(R.id.main_tab);
        rg_bottombar = (RadioGroup) main_tab.findViewById(R.id.rg_bottombar);

//        mFragmentContainer = (FrameLayout) findViewById(R.id.mFragmentContainer);
        fragmentMap = new HashMap<>();
        fragmentMap.put(R.id.rb_recommend, new RecommendFragment());
        fragmentMap.put(R.id.rb_community, new com.warmlight.voicepacket.fragment.main.CommunityFragment());
        fragmentMap.put(R.id.rb_playlist, new MeFragment());
//        fragmentMap.put(R.id.rb_me, new MeFragment());

        mTabsMap = new HashMap<>();
        mTabsMap.put(R.id.rb_recommend, "推荐页");
        mTabsMap.put(R.id.rb_community, "星球页");
        mTabsMap.put(R.id.rb_playlist, "播单页");

        //初始化的时候如果不同时加入会导致初始化完毕后我的页面没有初始化，如果用户不点击我的页面进行操作，或导致数据异常
        getSupportFragmentManager().beginTransaction()
                .add(R.id.mFragmentContainer,fragmentMap.get(R.id.rb_recommend))
                .add(R.id.mFragmentContainer,fragmentMap.get(R.id.rb_community))
                .add(R.id.mFragmentContainer,fragmentMap.get(R.id.rb_playlist))
                .commit();

        rg_bottombar = (RadioGroup) findViewById(R.id.rg_bottombar);
        rg_bottombar.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

//                prePageIndex = checkedId;// 记录这次统计页面的id
                changeFragment(checkedId);
                switch (checkedId) {
                    case R.id.rb_playlist:
                        EventBus.getDefault().post(new TeaseHideFloat(true));
                        QmzbVideoPlayer.onPlayOnPause();
                        MobclickAgent.onEvent(getContext(), MobClickHelper.botbar_dis);
                        break;
                    case R.id.rb_community:
                        EventBus.getDefault().post(new TeaseHideFloat(false));

                        if (SharePreferenceUtil.getInstance(MainActivity.this).getInt(SharedPerfenceConstant.COMMTABTYPE)==0){
                            OttoBus.getInstance().post(new ORecommBean(OttoConstants.COMMPLAY,""));
                        }else if (SharePreferenceUtil.getInstance(MainActivity.this).getInt(SharedPerfenceConstant.COMMTABTYPE)==1){
                            OttoBus.getInstance().post(new OVideoBean(OttoConstants.COMMPLAY,""));
                        }
                        MobclickAgent.onEvent(getContext(), MobClickHelper.botbar_pla);
                        break;
                    case R.id.rb_recommend:
                        EventBus.getDefault().post(new TeaseHideFloat(true));
                        QmzbVideoPlayer.onPlayOnPause();
                        MobclickAgent.onEvent(getContext(), MobClickHelper.botbar_mine);
                        break;
                    default:
                        break;
                }
            }
        });
//        prePageIndex = R.id.rb_playlist;// 默认页面赋值为推荐页
        changeFragment(rg_bottombar.getCheckedRadioButtonId());// 初始化显示第一页
    }

    /**
     * .add(R.id.mFragmentContainer,fragmentMap.get(R.id.rb_recommend))
     .add(R.id.mFragmentContainer,fragmentMap.get(R.id.rb_playlist))
     .commit();
     * @param fragmentKey 修改页面切换逻辑，删除原逻辑。
     */
    private void changeFragment(int fragmentKey) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.hide(fragmentMap.get(R.id.rb_recommend))
            .hide(fragmentMap.get(R.id.rb_community))
            .hide(fragmentMap.get(R.id.rb_playlist))
            .show(fragmentMap.get(fragmentKey));
//        Fragment nextFragment = fragmentMap.get(fragmentKey);
//        if (currentFragment == null) {
//            ft.add(R.id.mFragmentContainer, currentFragment = nextFragment);
//        } else {
//            if (nextFragment.isAdded()) {
//                ft.hide(currentFragment);
//                ft.show(currentFragment = nextFragment);
//            } else {
//                ft.hide(currentFragment);
//                ft.add(R.id.mFragmentContainer, currentFragment = nextFragment);
//            }
//        }

        // ft.commit();
        ft.commitAllowingStateLoss();
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            if ((System.currentTimeMillis() - mExitTime) > DURING) {
//                Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
//                mExitTime = System.currentTimeMillis();
//            } else {
//                System.exit(0);
//            }
//            return true;
//        }
//        return super.onKeyDown(keyCode, event);
//    }

    /**
     * 创建悬浮窗，需要先进行权限判断
     */
    private void createWindow(){
//        checkFloatWindowPermission();//测试悬浮框时使用
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

            if(SPUtils.isFloatWindowNotice()){
                //首次进入无论如何都提示
                checkFloatWindowPermission();
                SPUtils.setFloatWindowNotice(false);
            }else{
                if (Settings.canDrawOverlays(this)) {
                    startService(new Intent(MainActivity.this, FloatWindowService.class));
                    return;
                }

                if (!Settings.canDrawOverlays(this)) {// && SPUtils.isFloatWindowNotice()) {
                    checkFloatWindowPermission();
                    return;
                }

    //        if (!SPUtils.isFloatWindowNotice()) {
                startService(new Intent(MainActivity.this, FloatWindowService.class));
    //        }else{
    //            checkFloatWindowPermission();
    //        }
            }
        }else{
            startService(new Intent(MainActivity.this, FloatWindowService.class));
            SPUtils.setFloatWindowNotice(false);
        }
    }

    @Override
    public void onPermissionGranted(PermissionGrantedResponse response) {
//        Log.e("TAG","用户允许权限");
        createWindow();
    }

    @Override
    public void onPermissionDenied(PermissionDeniedResponse response) {
//        Log.e("TAG","未获得权限");
        showDeniedDialog();
    }

    @Override
    public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
//        Log.e("TAG","解释");
        if(!SPUtils.isPermissionNoticed()){
            showRationaleShouldBeShownDialog(token);
            SPUtils.setPermissionNotice(true);
        }
    }

    /**
     * 用户不允许权限，向用户说明权限的重要性，并支持用户去设置中开启权限
     */
    private void showDeniedDialog(){
//        new AlertDialog.Builder(MainActivity.this).setTitle("请允许获取存储空间")
//                .setMessage("无法获取此权限，不能正常工作")
//                .setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
//                    @Override public void onClick(DialogInterface dialog, int which) {
//                        dialog.dismiss();
//                    }
//                })
//                .setPositiveButton("去设置", new DialogInterface.OnClickListener() {
//                    @Override public void onClick(DialogInterface dialog, int which) {
//                        Intent intent = new Intent();
//                        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
//                        intent.setData(Uri.parse("package:"+MainActivity.this.getPackageName()));
//                        intent.putExtra("cmp", "com.android.settings/.applications.InstalledAppDetails");
//                        intent.addCategory("android.intent.category.DEFAULT");
//                        MainActivity.this.startActivity(intent);
//                        dialog.dismiss();
//                    }
//                })
//                .show();
        new AlertDialog.Builder(MainActivity.this).setTitle("请允许获取开启悬浮窗")
                .setMessage("无法获取此权限，不能正常工作")
                .setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
                    @Override public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .setPositiveButton("去设置", new DialogInterface.OnClickListener() {
                    @Override public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                                Uri.parse("package:" + getPackageName()));
//                        MainActivity.this.startActivityForResult(intent);
                        dialog.dismiss();
                    }
                })
                .show();
    }

//    private void showShare() {//分享的
//        OnekeyShare oks = new OnekeyShare();
//        //关闭sso授权
//        oks.disableSSOWhenAuthorize();
//
//        // title标题，微信、QQ和QQ空间等平台使用
//        oks.setTitle("分享");
//        // titleUrl QQ和QQ空间跳转链接
//        oks.setTitleUrl("http://sharesdk.cn");
//        // text是分享文本，所有平台都需要这个字段
//        oks.setText("我是分享文本");
//        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//        oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
//        // url在微信、微博，Facebook等平台中使用
//        oks.setUrl("http://sharesdk.cn");
//        // comment是我对这条分享的评论，仅在人人网使用
//        oks.setComment("我是测试评论文本");
//        // 启动分享GUI
//        oks.show(this);
//    }

    /**
     * 用户不允许权限，向用户说明权限的重要性
     * @param token
     */
    private void showRationaleShouldBeShownDialog(final PermissionToken token){
        new AlertDialog.Builder(MainActivity.this,android.R.style.Theme_Material_Light_Dialog_Alert).setTitle("提示")
                .setMessage("记录您的播放记录需要存储空间的权限，不开启将无法正常工作！")
                .setCancelable(false)
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        token.cancelPermissionRequest();
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        token.continuePermissionRequest();
                    }
                })
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override public void onDismiss(DialogInterface dialog) {
                        token.cancelPermissionRequest();
                    }
                })
                .show();
    }


    /**
     * 修复部分手机 播放服务意外停止无法播放音频的问题
     */
    @Override
    public void onResume() {
        super.onResume();

//        QmzbVideoPlayer.onPlayOnResume();

        if (!isServiceWork(getContext(),"com.warmlight.voicepacket.AudioService")){
            startService(new Intent(MainActivity.this,AudioService.class));
        }
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    //悬浮窗提示用户
    private void checkFloatWindowPermission(){
        //如果需要提示用户开启悬浮窗权限
//        if(SPUtils.isFloatWindowNotice()){
            startActivity(new Intent(MainActivity.this,FloatWindowPermissionActivity.class));
//        }
    }


    private long a = 0;
    @Override
    public void onBackPressed() {
        if (QmzbVideoPlayer.backPress()) {
            return;
        }
        long currentTimeMillis = TimeFormatUtils.getCurrentTimeMillis();
        if (currentTimeMillis-a>2500){
            a = TimeFormatUtils.getCurrentTimeMillis();
            showToast("再点一次退出应用");
        }else{
            super.onBackPressed();
        }

    }
}
